package com.leyou.common.advice;

import com.leyou.common.enums.LyEnum;
import com.leyou.common.exception.LyException;
import com.leyou.common.vo.ExceptionResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class CommonExceptionHandler {
    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> handler(LyException e){
        LyEnum lyEnum = e.getLyEnum();
        return ResponseEntity.status(lyEnum.getCode()).body(new ExceptionResult(lyEnum));
    }
}
